﻿#include "CanvasWindow.h"


CanvasWindow::CanvasWindow(wxWindow* parent, const wxPoint& point, const wxSize& size)
	:ssGLPanel(parent, point, size)
{
	m_gameWorld.Init();
}

CanvasWindow::~CanvasWindow(void)
{
}

void CanvasWindow::OnExit()
{
}

void CanvasWindow::OnMouseMove(wxMouseEvent& ev)
{
	if (ev.RightIsDown())//按键按下
	{
		ssWndCoord ChangedPoint = { ev.GetX() - m_RLastPoint.x, ev.GetY() - m_RLastPoint.y };
		m_RLastPoint.x = ev.GetX();
		m_RLastPoint.y = ev.GetY();
		m_gameWorld.OnMouseMove(ChangedPoint.x, ChangedPoint.y);
	}
}

void CanvasWindow::OnMouseWheel(wxMouseEvent& ev)
{
	m_gameWorld.OnMouseWheel(ev.GetWheelRotation());
}

void CanvasWindow::OnLeftMouseUp(wxMouseEvent & ev)
{
	m_gameWorld.OnLeftUp(ev.GetX(), ev.GetY());
}

void CanvasWindow::OnKeyDown(wxKeyEvent& ev)
{
    int key = ev.GetKeyCode();
	m_gameWorld.OnKeyDown(key);
}

void CanvasWindow::OnKeyUp(wxKeyEvent& ev)
{
}

void CanvasWindow::OnRender()
{
	m_gameWorld.Render();
}
